/*
 * @Descripttion: 
 * @Author: cuidm
 * @Date: 2020-10-10 17:27:42
 * @LastEditors: cuidm
 * @LastEditTime: 2020-10-16 16:15:21
 */
import React, { useState, useEffect } from "react";
import { Button, Modal, Input, Form } from "antd";

const { confirm } = Modal

const HcpModal = ({ className, title, visible, onFinish, cancel, content, type, ...props }) => {

	useEffect(() => {
		if (visible && type == "confirm") showConfirmModal();
	}, [visible])

	const showConfirmModal = () => {
		confirm({
			prefixCls: "hcp-modal",
			okButtonProps: { prefixCls: "hcp-btn" },
			cancelButtonProps: { prefixCls: "hcp-btn" },
			title: title,
			content: content,
			onCancel() {
				if (typeof cancel == "function") cancel();
			},
			onOk() {
				if (typeof onFinish == "function") onFinish();
			},
		});
	}

	return (
		<>
			{
				type != "confirm" &&
				<Modal
					title={title}
					visible={visible}
					footer={null}
					onCancel={cancel}
					destroyOnClose
					className={className}
					{...props}
				>
					<Form
						labelCol={{ span: 5 }}
						wrapperCol={{ span: 19 }}
						onFinish={onFinish}
					>
						{content}
						<div className="hcp-modal-body-footer">
							<Form.Item wrapperCol={{ span: 24 }} >
								<Button onClick={cancel}>取消</Button>
								<Button type="primary" htmlType="submit">确定</Button>
							</Form.Item>
						</div>
					</Form>
				</Modal>
			}
		</>
	);
};
export default HcpModal;